package com.leetcode.solution.s8x;

import com.leetcode.solution.model.ListNode;

import java.util.HashMap;

public class DeleteDuplicates82 {
    public static void main(String[] args) {
        ListNode head = createLinklist();

        ListNode result = new DeleteDuplicates82().deleteDuplicates(head);
        while (result != null) {
            System.out.print(result.val);
            result = result.next;
        }

    }

    private static ListNode createLinklist() {
        ListNode head = new ListNode(1);
        ListNode node = head;
        node.next = new ListNode(2);
        node = node.next;

        node.next = new ListNode(3);
        node = node.next;

        node.next = new ListNode(3);
        node = node.next;

        node.next = new ListNode(4);
        node = node.next;

        node.next = new ListNode(4);
        node = node.next;

        node.next = new ListNode(5);

        return head;
    }

    public ListNode deleteDuplicates(ListNode head) {
        ListNode root = new ListNode(0, head);
        ListNode currentNode = root;

        HashMap<String, String> m = new HashMap<>();
        int tmp;
        while (currentNode.next != null && currentNode.next.next != null) {
            if (currentNode.next.val == currentNode.next.next.val) {
                tmp = currentNode.next.val;
                while (currentNode.next != null && currentNode.next.val == tmp) {
                    currentNode.next = currentNode.next.next;
                }
            } else {
                currentNode = currentNode.next;
            }
        }

        return root.next;
    }
}
